package aidturith.db.beans;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@Entity
@Table(name = "circle_table")
public class Circle {

	@Id
	@GeneratedValue
	@Column(name = "circle_id")
	private int circle_id;

	@Column(name = "circle_name", nullable = false, updatable = true, unique = false)
	private String circle_name;

	@Column(name = "circle_date", nullable = true, updatable = true, unique = false)
	private int circle_date;

	@Column(name = "circle_web", nullable = true, updatable = true, unique = false)
	private String circle_web;

	@OneToMany(mappedBy="circle")
	@Cascade({CascadeType.ALL})
	private Set<Artist> artists = new HashSet<Artist>();

	@ManyToMany(cascade = {javax.persistence.CascadeType.ALL})
	@JoinTable(name="album_circle_table",
	joinColumns={@JoinColumn(name="circle_id")},
	inverseJoinColumns={@JoinColumn(name="album_id")})
	private Set<Album> albums = new HashSet<Album>();

	public Circle() {
		super();
	}

	public Circle(String circle_name) {
		super();
		this.circle_name = circle_name;
	}

	public Circle(String circle_name, int circle_date) {
		super();
		this.circle_name = circle_name;
		this.circle_date = circle_date;
	}

	public String getCircle_name() { return circle_name; }
	public void setCircle_name(String circle_name) { this.circle_name = circle_name; }

	public int getCircle_date() { return circle_date; }
	public void setCircle_date(int circle_date) { this.circle_date = circle_date; }

	public String getCircle_web() { return circle_web; }
	public void setCircle_web(String circle_web) { this.circle_web = circle_web; }

	public Set<Artist> getArtists() { return artists; }
	public void setArtists(Set<Artist> artists) { this.artists = artists; }

	public void addArtist(Artist artist) {
		getArtists().add(artist);
		artist.setCircle(this);
	}

	public Set<Album> getAlbums() { return albums; }
	public void setAlbums(Set<Album> albums) { this.albums = albums; }

	public void addAlbum(Album album) {
		getAlbums().add(album);
		album.getCircles().add(this);
	}

	@Override
	public String toString() { return circle_name; }

}
